<!DOCTYPE html>
<html lang="zh-cmn-Hans">
	<head>
		<meta http-equiv="Expires" content="0"/>
		<meta http-equiv="Pragma" content="no-cache"/>
		<meta http-equiv="Cache-control" content="no-cache"/>
		<meta http-equiv="Cache" content="no-cache"/>
		<meta charset="utf-8"/>
		<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
		<title>IT资产登记程序</title>
		<link rel="stylesheet" href="../layui/css/layui.css"/>
	</head>
	<body>
		<fieldset class="layui-elem-field site-demo-button">
			<legend><big><b>IT资产登记程序</b></big></legend>
			<div class="layui-fluid layui-form layui-form-pane">
				<div class="layui-row layui-form-item">
					<label class="layui-form-label">扫描二维码:</label>
					<div class="layui-input-block">
						<input class="layui-input" placeholder="流程: EM00000(可扫多个工号,重扫删除本身) -> TDIT00000 -> 登记成功!" id="qr" type="text"/>
					</div>
				</div>
			</div>
		</fieldset>
		<fieldset class="layui-elem-field site-demo-button">
			<legend><big><b>这里是当前扫描的信息组合</b></big></legend>
			<div id="DQ" class="layui-fluid layui-form layui-form-pane">
				注:<big><b>※</b></big>号为必扫项目
				<div class="layui-row">
					<div class="layui-col-sm6">
						<label class="layui-form-label"><big><b>※</b></big>责任人工号:</label>
						<div class="layui-input-block">
							<input class="layui-input" readonly=true placeholder="这里是必填项※责任人工号(请扫入工号)" id="YGGH" type="text"/>
						</div>
					</div>
					<div class="layui-col-sm6">
						<label class="layui-form-label">责任人姓名:</label>
						<div class="layui-input-block">
							<input class="layui-input" readonly=true placeholder="这里是责任人姓名(根据工号自动产生)" id="YGXM" type="text"/>
						</div>
					</div>
				</div>
				<div class="layui-row">
					<div class="layui-col-sm6">
						<label class="layui-form-label"><big><b>※</b></big>IT资产编号:</label>
						<div class="layui-input-block">
							<input class="layui-input" readonly=true placeholder="这里是必填项※当前资产编号(请扫入资产编号)" id="DQZC" type="text"/>
						</div>
					</div>
					<div class="layui-col-sm4 layui-col-sm-offset1 ">
						<button id="QK" class="layui-btn layui-btn-primary"><big><b>※</b></big>清空责任人</button >
				</div>
			</div>
		</fieldset>
		<fieldset class="layui-elem-field site-demo-button">
			<legend><big><b>IT资产信息(只Show当前资产的信息)</b></big></legend>
			<div class="layui-row">	
				<table class="layui-table lay-even">
					<thead>
						<tr class="table-active">
							<th width="10%" scope="col">IT资产编号</th>
							<th width="30%" scope="col">责任人</th>
							<th width="17%" scope="col">登记时间</th>
						</tr>
					</thead>
					<tbody id="blues">
					</tbody>
				</table>
			</div>
		</fieldset>
		<!-- 加载jQuery文件 -->
		<script src="../js/jquery.min.js"></script>
		<!-- 加载类ui文件 -->
		<script src="../layui/layui.js"></script>
		<!-- 写脚本 -->
		<script>
			var XH = {}//序号的字典
			var YGGH = {}//员工工号的字典
			var DTT = {}//时间截的字典
			var XM = {}//姓名的字典
			var BG = {}//保管人信息的字典
			var htmlstr = "";//网页的文本
			var QRC = "";
			$(document).ready(function(){//这里是画面准备完毕后执行的程式
				layui.use(['layer','form','element'], function(){//载入layui模块
					layer.msg('初始化正常！请扫工号牌。');//layer弹出层,form表单,element元素组件做分页或其他
					$.ajax({//阿贾克斯
						type:'GET',
						url: "http://172.31.3.27:84/index.php?s=/tdled/zi_chan/sel",//POST傳一個超長字串到後端
						dataType : "JSON",
						success: function(sss){
							layer.msg('查询成功');//,返回信息: '+sss);
							//把姓名循环写到XM的字典里面
							for(var i=0;i<sss['XM'].length;i++){
								XM[sss['XM'][i]['QR']] = sss['XM'][i]['Name'];
							}
							for(var i=0;i<sss['ZC'].length;i++){
								XH[sss['ZC'][i]['assets']] = sss['ZC'][i]['id'];
								YGGH[sss['ZC'][i]['assets']] = sss['ZC'][i]['yggh'];
								DTT[sss['ZC'][i]['assets']] = sss['ZC'][i]['dtt'];
								BG = {}
								htmlstr = "";
								htmlstr = "<tr><td>" + sss['ZC'][i]['assets'] + "</td><td>" + sss['ZC'][i]['yggh'] + "丨" + sss['ZC'][i]['FenZu'] + "丨" + sss['ZC'][i]['Name'] + "</td><td>" +  sss['ZC'][i]['dtt'] + "</td></tr>";
								$("#blues").prepend(htmlstr);
							}
						}//成功尾巴
					});//阿贾克斯程序尾巴
				});
				$("#qr").select();//画面准备完毕后就选择扫码输入框
			});

			$("#qr").click(function(){//扫描框被点击就选择内容
				$("#qr").select();
			});

			$("#qr").keypress(function(e){//这里是扫描输入框的回车按下后执行的程式
				if(e.keyCode === 13){//如果按下的键值是回车键13就执行以下语句
					$("#qr").select();//扫描输入框选择
					QRC = $("#qr").val();//定义局部变量QRC=扫描输入框的值

					if(/^EM\d{5}$/.test(QRC)){
						//layer.msg("正则通过");
						if(XM[QRC]){
							//layer.msg("包含在姓名列表内");
							if(BG[QRC]){
								delete BG[QRC];
								layer.msg("删除字典");
								DMstr = "";//代码文本
								YYstr = "";//原因文本
								for(var key in BG){
									try{
										var value = eval("BG['" +  key +"']");
										if(DMstr){
											DMstr += ";"+key;
											YYstr += ";"+value;
										}else{
											DMstr = key;
											YYstr = value;
										}
									}catch(e){}
								}
								$("#YGGH").val(DMstr);
								$("#YGXM").val(YYstr);
							}else{
								DMstr = "";//代码文本
								YYstr = "";//原因文本
								BG[QRC] = XM[QRC];
								for(var key in BG){
									try{
										var value = eval("BG['" +  key +"']");
										if(DMstr){
											DMstr += ";"+key;
											YYstr += ";"+value;
										}else{
											DMstr = key;
											YYstr = value;
										}
									}catch(e){}
								}
								$("#YGGH").val(DMstr);
								$("#YGXM").val(YYstr);
							}
						}else{
							layer.msg("不包含在异常列表内,请新增原因代码");
						}
						localStorage.yggh = DMstr;
						localStorage.ygxm = YYstr;
					}else if(/^T[A-Z]{3}\d{5,7}$/.test(QRC)){
						$("#DQZC").val(QRC);
						console.log(QRC);
						$.ajax({
							type:'POST',
							url: "http://172.31.3.27:84/index.php?s=/tdled/zi_chan/ins",//POST傳一個超長字串到後端
							data:"yggh="+$("#YGGH").val()+"&zichan="+$("#DQZC").val(),
							dataType : "JSON",
							success: function(sss){
								$("#blues").html("");
								for(var i=0;i<sss['ZC'].length;i++){
									XH[sss['ZC'][i]['assets']] = sss['ZC'][i]['id'];
									YGGH[sss['ZC'][i]['assets']] = sss['ZC'][i]['yggh'];
									DTT[sss['ZC'][i]['assets']] = sss['ZC'][i]['dtt'];
									htmlstr = "";
									htmlstr = "<tr><td>" + sss['ZC'][i]['assets'] + "</td><td>" + sss['ZC'][i]['yggh'] + "丨" + sss['ZC'][i]['FenZu'] + "丨" + sss['ZC'][i]['Name'] + "</td><td>" +  sss['ZC'][i]['dtt'] + "</td></tr>";
									$("#blues").prepend(htmlstr);
								}
								BG = {}
							}
						});
					}else{
						layer.msg('<div style="background-color: #FF5722;"><big><b>当前二维码无法运行，<br/>请确认当前进出烤信息<br/>必填项是否都有扫入！</b></big></div>');
					}
				}//回车的程序尾巴
			});

			$("#QK").click(function(){
				BG = {} //保管人的字典,这里是清空
				$("#YGGH").val("");
				$("#YGXM").val("");
			});

			$("#qr").blur(function(){
				layer.msg('输入框焦点失去了,将重新选择输入框!<br/><small><small>ps:此提示会自动消失</small></small>');
				$("#qr").select();
			});

			Date.prototype.format = function(fmt){//这里是日期格式化公式
				var o = {//格式化文本的正则表达式对照表(巧妙的用法)
					"M+" : this.getMonth()+1,								//月份
					"d+" : this.getDate(),										//日
					"h+" : this.getHours(),										//小时
					"m+" : this.getMinutes(),								//分
					"s+" : this.getSeconds(),									//秒
					"q+" : Math.floor((this.getMonth()+3)/3),		//季度
					"S"  : this.getMilliseconds()								//毫秒
				}//对照表尾巴
				if(/(y+)/.test(fmt)){//先判断有多少个y(年的格式)
					fmt=fmt.replace(RegExp.$1, (this.getFullYear()+"").substr(4 - RegExp.$1.length)); 
				}//年格式的尾巴
				for(var k in o){//循环k
					if(new RegExp("("+ k +")").test(fmt)){//对年月日时分秒毫秒的格式判断
						fmt = fmt.replace(RegExp.$1, (RegExp.$1.length==1) ? (o[k]) : (("00"+ o[k]).substr((""+ o[k]).length)));
					}//月日时分秒毫秒的格式化文本正则验证尾巴
				}//k的尾巴
				return fmt;
			}//日期格式化的程序尾巴
		</script>
	</body>
</html>